<template>
  <div id="search-history">
    <van-cell-group inset>
      <van-cell title="搜索历史">
        <div v-if="isShow">
          <span @click="$emit('delHistoryAll', [])">全部删除</span>
          &nbsp;&nbsp;&nbsp;
          <span @click="isShow = false">完成</span>
        </div>
        <van-icon name="delete" v-if="!isShow" @click="isShow = true" />
      </van-cell>
      <van-cell
        v-for="(history, index) in searchHistory"
        :key="index"
        :title="history"
        @click="onDelHostory(history, index)"
      >
        <van-icon name="close" v-if="isShow" />
      </van-cell>
    </van-cell-group>
  </div>
</template>
<script>
// import { setStorage } from '@/utils/storage'
export default {
  name: 'search-history',
  data () {
    return {
      isShow: false
    }
  },
  created () {},
  methods: {
    onDelHostory (history, index) {
      if (this.isShow) {
        // 删除状态
        this.searchHistory.splice(index, 1)
        // setStorage('search-history', this.searchHistory)
      } else {
        // 非删除则搜索
        this.$emit('search', history)
      }
    }
  },
  components: {},
  props: {
    searchHistory: {
      type: Array,
      required: true
    }
  },
  watch: {},
  computed: {},
  mounted () {}
}
</script>

<style lang="less" scoped></style>
